/*********************************************************************************
Organization 					: 				Georgia Institute of Technology
  
Institute 						:				Cognitive Computing Group(CCL)
 
Authors							: 				Manish Mehta 
 												
Class							:				NoResPeasKilledFP
 
Function						: 				A class for detecting the pattern 
												of having no resources because of 
												a peasant getting killed 
****************************************************************************/

package behavioradaptation.failurepattern;

import java.util.List;
import java.util.Vector;

import trace.Entry;
import trace.Trace;
import base.WargusStateImporter;
import behavioradaptation.analysisdata.AbstractedTrace;
import behavioradaptation.analysisdata.FailureTypes;
import behavioradaptation.analysisdata.FixData;
import behavioradaptation.analysisdata.KillData;
import behavioradaptation.analysisdata.PlanFailuresData;

public class NoResPeasKilledFP {
	public boolean detectPattern(List<PlanFailuresData> a_planFailuresList, AbstractedTrace a_abstractedtrace, FixData a_fxdata)
	{
		boolean patternfound = false;
		Trace a_trace = a_abstractedtrace.getTrace();
		Vector<KillData> a_killDataList = a_abstractedtrace.getKillData();
		for(int i = 0; i < a_planFailuresList.size(); i++)
		{
			PlanFailuresData pf = (PlanFailuresData)a_planFailuresList.get(i);
			List failurelist = pf.getFailures();
			for(int j = 0; j < failurelist.size(); j++)
			{	
				FailureTypes.m_failuretype  ftype  = (FailureTypes.m_failuretype) failurelist.get(j);
				if((ftype == FailureTypes.m_failuretype.NOT_ENOUGH_GOLD) ||
						(ftype == FailureTypes.m_failuretype.NOT_ENOUGH_OIL) ||
						(ftype == FailureTypes.m_failuretype.NOT_ENOUGH_WOOD))
				{
					int index = pf.getIndex();
					boolean fixfound = false;
					int noresourcecycle = (int)((Entry)a_trace.getTrace().get(index)).getTime();			
			
					for(int t = 0; t < a_killDataList.size(); t++)
					{
						KillData kdata = a_killDataList.get(t);
						if(kdata.getKillCycle() < noresourcecycle && kdata.getUnit().getType()==WargusStateImporter.unitTypeToInteger("peasant"))
						{
							patternfound = true;
							a_fxdata = new FixData();
							a_fxdata.m_pfd = pf;
							a_fxdata.m_kd = kdata;
							return patternfound;
						}
					}
					
				}
			}
		}
		return patternfound;
	}	
		
}
